<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>用户展示</title>
    <script src="../static/js/jquery.min.js"></script>

</head>
<body style="background: #f2f4f8;">
    <dev align="center">
        <h2>用户信息</h2>
        <table id="table"align="center">
            <tr>
                <th>用户名</th>
                <td>手机号</td>
                <th>权限</th>
                <th>操作</th>
            </tr>
            <tr>
                <td></td>
                <td></td>
                <td></td>
            </tr>
        </table>
    </dev>
</body>
<script type="text/javascript">
    $(function () {




        delUser = function(user){
            alert(user);
            $.ajax({
                url: '/api/user/deleteByUsername/'+user,
                dataType: 'json',
                type: 'GET',
                success: function (res) {
                    if (res.code == 100){
                        window.location.reload();
                        //alert("成功");
                    }else{
                        alert(res.message);
                    }
                }
            })
        };

        $.ajax({
            url: '/api/user/getAll',
            dataType : "json",
            type : "GET",
            success: function (res) {
                if (res.code == 100){
                    var row = '';
                    $(res.data).each(function () {
                        /*row += '<tr>' +
                            '<td>'+this.username+'</td>' +
                            '<td>'+this.roles+'</td>' +
                            ' <td><a href="#" onclick="delUser(this.username)">删除</a>&nbsp;<a href="#">修改</a></td>' +
                            ' </tr>';*/
                        row += `<tr>
                            <td>${this.username}</td>
                            <td>${this.mobile}</td>
                            <td>${this.roles}</td>
                             <td><a href="#" onclick="delUser(${this.username})">删除</a>&nbsp;<a href="/api/account/update?username=${this.username}">修改用户权限</a></td>
                            </tr>`
                    });
                    $("#table").append(row);
                }
            }
        })


    });


</script>
</html>